//
//  StudyUserGuideViewController.swift
//  SitPosition
//
//  Created by apple on 2019/4/20.
//  Copyright © 2019 apple. All rights reserved.
//

import Foundation
import UIKit
import Cartography


class StudyUserGuideViewController : GKNavigationBarViewController {
    
    // 标题
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.Color.primaryDarkTextColor
        label.font = Theme.Font.boldFont(ofSize: 26)
        label.numberOfLines = 1
        label.lineBreakMode = .byTruncatingTail
        label.text = Strings.studySettingAdvanceSettingUserGuide
        return label
    }()
    
    // 说明
    lazy var contentTV: UITextView = {
        let tv = UITextView()
        tv.isScrollEnabled = true
        tv.textAlignment = .left
        tv.font = Theme.Font.mediumFont(ofSize: 14)
        tv.textColor = Theme.Color.primaryDarkTextColor
        tv.backgroundColor = UIColor.clear
        tv.showsVerticalScrollIndicator = false
        tv.showsHorizontalScrollIndicator = false
        tv.text = Strings.userGuideContent
        return tv
    }()
    
    
    // MARK: - Object lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 导航栏
        gk_navBackgroundColor = UIColor.clear
        gk_navLeftBarButtonItem = UIBarButtonItem(imageName: "ic_nav_back_black", target: self, action: #selector(_backButtonTapped))
        
        // 设置子视图
        view.addSubviews([titleLabel, contentTV])
        _setupConstraints()
        view.backgroundColor = Theme.Color.primaryBackgroundColor
    }
}


extension StudyUserGuideViewController {
    
    // 设置视图约束
    func _setupConstraints() {
        // titleLabel
        constrain(titleLabel, gk_navigationBar, view) { v, sibling, parent in
            v.top == sibling.bottom + 19
            v.left == parent.left + 16
            v.right == parent.right - 16
            v.height == 25
        }
        
        // contentTV
        constrain(contentTV, titleLabel, view) { v, sibling, parent in
            v.top == sibling.bottom + 15
            v.left == parent.left + 15
            v.right == parent.right - 15
            v.bottom == parent.bottom - 15
        }
    }
    
    // 返回按钮点击事件
    @objc func _backButtonTapped() {
        if presentingViewController != nil {
            dismiss(animated: true, completion: nil)
        } else {
            navigationController?.popViewController(animated: true)
        }
    }
}
